package com.young.msg.service.impl;

import com.young.common.util.AssertUtil;
import com.young.interfaces.log.annotation.Log;
import com.young.interfaces.msg.service.IMsgSiteLetterOutService;
import com.young.msg.model.SiteLetter;
import com.young.msg.model.enums.ESiteLetterReceiverTypeEnum;
import com.young.msg.model.enums.ESiteLetterSateEnum;
import com.young.msg.model.enums.ESiteLetterSenderTypeEnum;
import com.young.msg.service.ISiteLetterReceiveService;
import com.young.msg.service.ISiteLetterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 站内信
 *
 * @author wangjy
 * @date 2022/03/11 23:55:41
 */
@Service
public class MsgSiteLetterOutServiceImpl implements IMsgSiteLetterOutService {
    private static final Logger logger = LoggerFactory.getLogger(MsgSiteLetterOutServiceImpl.class);
    /**
     * 收信服务
     */
    @Autowired
    private ISiteLetterReceiveService siteLetterReceiveService;
    /**
     * 站内信服务
     */
    @Autowired
    private ISiteLetterService siteLetterService;


    /**
     * 给用户发送系统信件
     *
     * @param receiverUserId 收信人id
     * @param title          站内信标题
     * @param content        站内信内容
     */
    @Log("给用户发送系统信件")
    @Override
    public void sendSystemLetterToUser(String receiverUserId, String title, String content) {
        AssertUtil.notBlank(receiverUserId, "收信人不允许为空");
        AssertUtil.notBlank(title, "站内信标题不允许为空");
        AssertUtil.notBlank(content, "站内信内容不允许为空");
        SiteLetter letter = new SiteLetter();
        letter.setTitle(title);
        letter.setContent(content);
        letter.setSender("system");
        letter.setSenderName("system");
        letter.setSenderType(ESiteLetterSenderTypeEnum.SYSTEM.type);
        letter.setReceiver(receiverUserId);
        letter.setReceiverType(ESiteLetterReceiverTypeEnum.ONE.type);
        letter.setState(ESiteLetterSateEnum.SENDED.type);
        letter.setSendTime(new Date());
        letter.setCreateUserId("1");
        letter.setUpdateUserId("1");
        siteLetterService.insert(letter);
    }

    /**
     * 收取信件
     *
     * @param receiverUserId 收信人id
     */
    @Log("收取信件")
    @Override
    public void receiveLetter(String receiverUserId) {
        siteLetterReceiveService.receiveLetter(receiverUserId);
    }
}
